package com.jy.wms.common.base;

import com.jy.wms.common.SpringUtil;
import com.jy.wms.dao.WmsLibraryAreaMapper;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Map;

/**
 * Created by Administrator on 2018-04-13.
 */
public class libraryareaImportHanlder extends ExcelDataHandlerDefaultImpl {
    WmsLibraryAreaMapper wmsLibraryAreaMapper = SpringUtil.getBean(WmsLibraryAreaMapper.class);
    private static Logger log = LoggerFactory.getLogger(WmsLibraryAreaMapper.class);

    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        log.info("value:" + value);

        if (value instanceof Double) {
            NumberFormat nf = new DecimalFormat("#");
            value = nf.format(value);
        }
        if (originKey != "" && originKey != null) {
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }


    }

    private String getRealKey(String originKey) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession session = request.getSession();
        log.info("originKey:" + originKey);
        if (originKey.equals("库区名称")) {
            return "kqmc";
        }
        if (originKey.equals("库区代码")) {
            return "kqdm";
        }
        if (originKey.equals("备注")) {
            return "bz";
        }
        return "";
    }
}
